This sample demonstrates the easiest way to use Open Transport to download an HTTP URL from a web server. The code from this sample is featured in the latest release (v1.3) of the book “Inside Macintosh: Open Transport”.
Packing List
The package contains the following items items:
• OTSimpleDownloadHTTP-PPC.µ — A project to build the PPC version.
• OTSimpleDownloadHTTP-PPC — A compiled version of the above.
• OTSimpleDownloadHTTP-68K.µ — A project to build the 68K version.
• OTSimpleDownloadHTTP-68K — A compiled version of the above.
• OTSimpleDownloadHTTPTest.c — A test application that calls the uses the download module.
• OTSimpleDownloadHTTP.h — Interface to the download module.
• OTSimpleDownloadHTTP.c — A module that exports a single, simple routine to download an HTTP URL using OT.
Sample Requirements
I tested this code with OT 1.2 running under Mac OS 8 on both 68K and PPC. The code should run just fine with OT 1.1.1 or newer. I do not support this code on OT versions prior to 1.1.1.
There is a bug in OT 1.2 and earlier that prevents the 68K version of this sample from running on PPC machines. The specific problem is that OTUseSyncIdleEvents crashes when called from 68K code on a PPC. This bug has been fixed in OT 1.3.
Running the Sample
To run the sample, simply double click the application. You can then choose to either enter a number (to download one of the pre-defined URLs listed on the console window), or type in your own HTTP URL. The contents of the URL (including the HTTP headers!) will be placed in a file in the same folder as the application.
Building the Sample
The sample was built using the Metrowerks CodeWarrior 11 environment and the Open Transport 1.1.1 SDK interfaces and libraries.
To rebuild the sample, first open the project and change the “LatestInterfaces” and “LatestLibraries” access paths to point to the interfaces and libraries from the OT 1.1.1 (or newer) SDK. Then choose Make from the Project menu.
Credits and Version History
If you find any problems with this sample, mail <DevSupport@apple.com> with “Attn: Quinn” as the first line of your mail and I’ll try to fix them up.
Version 1.0d1 was the first release.
Version 1.0d2 corrects a style issue, where I was assigning an event code (lookResult), which will be positive, to a variable of type OSStatus.
Version 1.0d3 corrects a bug in the comments where I was recommending the use of "\0x13" instead of "\0x0d". Also brought the test URLs up to date with the recent ADR web site reorganisation.